package logic

import (
	"context"
	"pay_srv/pay"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HandlerOrderAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHandlerOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HandlerOrderAddLogic {
	return &HandlerOrderAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HandlerOrderAddLogic) HandlerOrderAdd(req *types.RequestOrderAdd) (resp *types.Response, err error) {

	add, err := l.svcCtx.PaySrv.OrderAdd(l.ctx, &pay.OrderAddRequest{
		UserId:  int32(req.UserId),
		GoodsId: int32(req.GoodsId),
		Num:     int32(req.Num),
		Status:  req.Status,
		PayType: req.PayType,
	})
	if err != nil {
		return &types.Response{
			Msg:  "订单创建失败",
			Code: "500",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "订单创建成功",
		Code: "200",
		Data: map[string]interface{}{
			"order": add,
		},
	}, nil
}
